package com.study.operateDB.Enum;

import java.util.Properties;

import com.study.operateDB.ReadProperties;

public enum Config {
	DB2, MYSQL, PGSQL, SQLSERVER, ORACEL;
	private static String DRIVER_NAME = "DB2";
	private static final String DRIVER = "DRIVER";
	private static final String IP = "IP";
	private static final String PORT = "PORT";
	private static final String DB_NAME = "DB_NAME";
	private static final String SID = "SID";
	private final Properties prop1;
	private final Properties prop2;
	private static String DB_SERVER="LOCAL_155";
	public static final String USER="USER";
	public static final String PASSWORD="PASSWORD";
	public enum ConfigServer {
		 LOCAL_155;
	}
	
	public static void setDB_SERVER(ConfigServer dB_SERVER) {
		DB_SERVER = dB_SERVER.name();
	}

	private Config() {
		prop1 = ReadProperties.readRroperties("DB_Driver.properties");
		prop2 = ReadProperties.readRroperties("DB_Config.properties");
		// System.out.println(this+"_DRIVER_CALSS");//System.out.println(prop.getProperty(this+"_DRIVER_CLASS"));
	}

	public String driverClass() {
		return prop1.getProperty(this.name() + "_DRIVER_CLASS");
	}

	public String uRLString() {
		switch (this) {
		case ORACEL:
			return prop1.getProperty(this.name() + "_URL_TEMPLATE")
					.replace(getReplacement(IP), getValue(IP))
					.replace(getReplacement(PORT), getValue(PORT))
					.replace(getReplacement(SID), getValue(SID));

		default:
			return prop1.getProperty(this.name() + "_URL_TEMPLATE")
					.replace(getReplacement(IP), getValue(IP))
					.replace(getReplacement(PORT), getValue(PORT))
					.replace(getReplacement(DB_NAME), getValue(DB_NAME));
		}
	}

	public String getValue(String ip2) {		
		return prop2.getProperty(DB_SERVER+"."+ip2);
	}

	public String getReplacement(String subKey) {
		return "{" + subKey + "}";
	}
}
